package com.example.yuanann.vegetable_app.fragment;

import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import com.example.yuanann.vegetable_app.R;

public class Study extends Fragment {

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_home_study, container, false);
        return view;
    }


    public void onActivityCreated(Bundle savedInstanceState) {

        super.onActivityCreated(savedInstanceState);
        super.onCreate(savedInstanceState);

        final Button cd,cq,xa,sh;

        cd = getActivity().findViewById(R.id.cd);
        cq = getActivity().findViewById(R.id.cq);
        xa = getActivity().findViewById(R.id.xa);
        sh = getActivity().findViewById(R.id.sh);

        Fragment c1 = new Study_list();
        //实例化管理器
        FragmentManager fragmentManager = getFragmentManager();
        //定义事务
        FragmentTransaction fta = fragmentManager.beginTransaction();
        //添加fragment
        fta.add(R.id.newsListShowView, c1);
        //提交事务`
        fta.commit();
        cd.setTextColor(Color.parseColor("#5bad56"));
        cq.setTextColor(Color.parseColor("#4f5555"));
        xa.setTextColor(Color.parseColor("#4f5555"));
        sh.setTextColor(Color.parseColor("#4f5555"));
        cd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //实例化fragment
                Fragment c1 = new Study_list();
                //实例化管理器
                FragmentManager fragmentManager = getFragmentManager();
                //定义事务
                FragmentTransaction fta = fragmentManager.beginTransaction();
                //添加fragment
                fta.replace(R.id.newsListShowView, c1);
                //提交事务`
                fta.commit();
                cd.setTextColor(Color.parseColor("#5bad56"));
                cq.setTextColor(Color.parseColor("#4f5555"));
                xa.setTextColor(Color.parseColor("#4f5555"));
                sh.setTextColor(Color.parseColor("#4f5555"));

            }
        });
        cq.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //实例化fragment
                Fragment c2 = new Study_list();
                //实例化管理器
                FragmentManager fragmentManager = getFragmentManager();
                //定义事务
                FragmentTransaction fta = fragmentManager.beginTransaction();
                //添加fragment
                fta.replace(R.id.newsListShowView, c2);
                //提交事务`
                fta.commit();
                cq.setTextColor(Color.parseColor("#5bad56"));
                cd.setTextColor(Color.parseColor("#4f5555"));
                xa.setTextColor(Color.parseColor("#4f5555"));
                sh.setTextColor(Color.parseColor("#4f5555"));
            }
        });
        xa.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //实例化fragment
                Fragment c3 = new Study_list();
                //实例化管理器
                FragmentManager fragmentManager = getFragmentManager();
                //定义事务
                FragmentTransaction fta = fragmentManager.beginTransaction();
                //添加fragment
                fta.replace(R.id.newsListShowView, c3);
                //提交事务`
                fta.commit();
                xa.setTextColor(Color.parseColor("#5bad56"));
                cd.setTextColor(Color.parseColor("#4f5555"));
                cq.setTextColor(Color.parseColor("#4f5555"));
                sh.setTextColor(Color.parseColor("#4f5555"));

            }
        });
        sh.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //实例化fragment
                Fragment c4 = new Study_list();
                //实例化管理器
                FragmentManager fragmentManager = getFragmentManager();
                //定义事务
                FragmentTransaction fta = fragmentManager.beginTransaction();
                //添加fragment
                fta.replace(R.id.newsListShowView, c4);
                //提交事务`
                fta.commit();
                sh.setTextColor(Color.parseColor("#5bad56"));
                cq.setTextColor(Color.parseColor("#4f5555"));
                cd.setTextColor(Color.parseColor("#4f5555"));
                xa.setTextColor(Color.parseColor("#4f5555"));

            }
        });

    }
}

